/*
 * Copyright (C) 2009 Kristopher T Babic
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses>.
 */

package edu.idp.client.applet;

import gjt.Util;
import edu.idp.client.MainMenuFrame;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author Kristopher T Babic
 */
public class InterDraw extends Applet implements ActionListener {
    private MainMenuFrame myFrame;
    private Font font;
    private boolean loaded = false;
    private Button startButton = null;

    public void init() {
//    this.setLayout(null);
        startButton = new Button("Start InterDraw");
        startButton.addActionListener(this);
//    startButton.setBounds(10,10,150,30);
        add(startButton);
        font = new Font("sansserif", Font.BOLD, 48);
    }

    public void paint(Graphics g) {
        super.paint(g);
/*
		g.setColor(Color.red);
		g.fillOval(7,7,336,106);
		g.setColor(Color.pink);
		g.fillOval(10,10,330,100);
		g.setColor(Color.black);
		g.setFont(font);
		if (!loaded)
			g.drawString("Please Wait", 40, 75);
		else
			g.drawString("Have Fun", 60, 75);
*/
    }

//  private void init_InterDraw() {


    public void start() {
/*
		Graphics g = getGraphics();
		paint(g);

		paint(g);
		g.dispose();

*/
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Start InterDraw")) {
            Util.setCursor(Cursor.WAIT_CURSOR, this);

            myFrame = new MainMenuFrame("InterDraw Collaborative Art Program", this);
            myFrame.init();


            Integer port = null;
            try {
                port = Integer.valueOf(getParameter("PORT"));
            }
            catch (Exception ex) {
            }

            String host = null;
            try {
                host = getParameter("HOST");
            }
            catch (Exception ex) {
            }

            String osName = System.getProperty("os.name");
            boolean solarisWorkaround = (osName != null && (osName.indexOf("Solaris") != -1 || osName.indexOf("Irix") != -1));

            int diff = 0;
            if (solarisWorkaround)
                diff = 25;

            myFrame.setSize(new Dimension(650 + diff, 650 + (2 * diff)));
            myFrame.setResizable(false);
            myFrame.setVisible(true);

            // remove later??
            myFrame.start(port, host);
            Util.setCursor(Cursor.DEFAULT_CURSOR, this);

        }
    }
}


